package cn.tedu.sp04.feign.fallback;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Component;

import cn.tedu.pojo.Item;
import cn.tedu.sp04.feign.ItemFeignService;
import cn.tedu.web.util.JsonResult;

@Component
public class ItemFeignServiceFB implements ItemFeignService {

	@Override
	public JsonResult<List<Item>> getItems(String orderId) {
		//降级代码，可以返回一段信息
		//也可以返回缓存数据
		
		//模拟返回缓存数据的过程
		if(Math.random()<0.5) {
			return JsonResult.ok(Arrays.asList(new Item[] {
					new Item(1,"缓存商品1",4),
					new Item(2,"缓存商品2",1),
					new Item(3,"缓存商品3",2),
					new Item(4,"缓存商品4",1),
					new Item(5,"缓存商品5",3)
			}));
		}
		return JsonResult.err("根据订单获取商品失败");
	}

	@Override
	public JsonResult decreaseNumbers(List<Item> items) {
		return JsonResult.err("减少商品库存失败");
	}

}
